package com.yesallchina.wxapp.officialaccount.context;


import org.springframework.context.ApplicationContext;
import org.springframework.util.StringUtils;

public class SpringApplicationContext {

    private ApplicationContext appCtx;

    public SpringApplicationContext(ApplicationContext appCtx){
        this.appCtx = appCtx;
    }

    public <T> T getBean(String classPathName) {
        if (!StringUtils.hasText(classPathName)){
            return null;
        }
        try {
            Class clz = Class.forName(classPathName);
            return (T) appCtx.getBean(clz);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

}
